// pages/scenic/scenic.js
const util = require('../../utils/util.js')
const app = getApp();
const cloudUrl = app.globalData.cloudUrl;
const tempUrl = cloudUrl+"shop-menu-icon11.png";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    loadInfo:{},
    cloudUrl:app.globalData.cloudUrl,
    //幻灯片
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    circular: false,
    interval: 2000,
    duration: 500,
    previousMargin: 0,
    nextMargin: 0,
    swiperUrls:["ms/1.jpg","ms/2.jpg"],
    
    tmpData1:{img:cloudUrl+"menu/jd.png",name:"酒店简介",showLine:true},
    tmpData2:{img:cloudUrl+"menu/jq.png",name:"松阳县新兴镇",showLine:false},
    tmpTData1:{img:cloudUrl+"menu/ms.png",name:"酒店房型"},
    tmpTData2:{img:cloudUrl+"menu/jd.png",name:"周边酒店"},
    ticketsList:[{id:1, name:"大木山茶园景区观光车游览套票", price:30, oldPrice:30, time:"18:00"}],
    buyBtnUrl:cloudUrl+"buyBtn.png",
    endPosY:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var loadInfo = JSON.parse(options.data);
    this.setData({loadInfo:loadInfo});
    //console.log("======");
    //console.log(options);
    var tmp = this.data.tmpData2;
    tmp.name = loadInfo.locationName;
    this.setData({
      swiperUrls:loadInfo.swipers,
      tmpData2:tmp
    })
    wx.setNavigationBarTitle({
      title: loadInfo.name,
    })
    this.setRoomList();

    //处理周边酒店 高度铺满的逻辑
    /**const query = wx.createSelectorQuery();
    const qq = query.select('#testId').boundingClientRect();
    const _this = this;
    qq.exec(function(res){
      //console.log(res[0].top);
      _this.setData({endPosY:res[0].top});
    })**/
  },
  setRoomList(){
    //门票列表
    const app = getApp();
    var allList = app.globalData.hotelRoomList;
    const _this = this;//
    if(allList.length <= 0){
      //获取酒店房型列表
      wx.cloud.callFunction({
        name: 'quickstartFunctions',
        data:{
          type:"getDataList",
          todos:"hotelRoomList"
        },
        complete: res => {
          console.log('get hotelRoomList: ', res);
          const arr = res.result.data;
          app.globalData.hotelRoomList = arr;
          _this.exeSetRooms();
        }
      })
    }
    else{
      this.exeSetRooms();
    }
  },
  exeSetRooms(){
    const app = getApp();
    var allList = app.globalData.hotelRoomList;
    var curList = [];
    var arr = this.data.loadInfo.tickets;
    //console.log("3242423=="+arr);//
    for(var i=0; i<allList.length; i++){
      //console.log("lsdks=="+allList[i]._id);
      if(arr.indexOf(allList[i].id+"") != -1){
        curList.push(allList[i]);////
      }
    }
    //console.log("222222=="+curList);//
    this.setData({
      ticketsList:curList
    })
  },
  onDetailsClick(e){
    const params = JSON.stringify(this.data.loadInfo);
    util.gotoScenicDetailsPage(params);
  },
  onMapClick(e){
    var arr = [];//119.17225,29.02827
    if(this.data.loadInfo.location){
      arr = this.data.loadInfo.location.coordinates;
      //console.log("景区地图坐标：");
      //console.log(arr);
    }
    const str = JSON.stringify(arr);
    util.gotoMapPage(str);
  },
  onTicketsBuyClick(e){
    const idx = e.currentTarget.dataset.index;
    console.log("idx="+idx);
    var curInfo = this.data.ticketsList[idx];
    curInfo = JSON.stringify(curInfo);
    // util.gotoTicketsBuyPage(curInfo);
    util.gotoHotelBuyPage(curInfo);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})